package com.gxa.springboot229.service.impl;

import com.gxa.springboot229.mapper.AdminMapper;
import com.gxa.springboot229.pojo.Admin;
import com.gxa.springboot229.service.AdminService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service("adminService")
public class AdminServiceImpl implements AdminService  {
    @Resource
    AdminMapper adminMapper;

    /**
     * 登录接口
     * @param phone
     * @param pwd
     * @return
     */
    @Override
    public Integer login (String phone, String pwd) {
        Admin admin = new Admin();
        admin.setPhone(phone);

        int hui = 0;
        //查询是否有一条此电话 和 验证密码
        if( adminMapper.selectCount(admin) == 1){
            if(adminMapper.selectOne(admin).getPwd().equals(pwd)){
                hui = 1;
            }
        }
        return hui;
    }

    /**
     * 修改接口， 可以修改电话 和 密码
     * @param admin
     * @return
     */
    @Override
    public int update (Admin admin) {
       admin.setName(null);
        return adminMapper.updateByPrimaryKeySelective(admin);
    }

    /**
     * 查询接口，查询自身的东西
     * @return
     */
    @Override
    public List<Admin> findamdin (int id) {
        Admin admin = new Admin();
        admin.setId(id);
        List <Admin> admins = adminMapper.select(admin);
        admins.get(0).setPwd(null);
        return admins;
    }

    /**
     * 通过电话查询
     * @param phone
     * @return
     */

    @Override
    public Integer findByPhone (String phone) {
        Admin admin = new Admin();
        admin.setPhone(phone);
        return adminMapper.selectCount(admin);
    }
}
